Subject: CustomNew.cp Author: Francois Pottier Uploaded By: AFC Radix1 Date: 11/19/1995 File: CustomNew.cp (8383 bytes) Estimated Download Time (60658 baud): < 1 minute Download Count: 101 Needs: C++ compiler Keywords: C++ OPERATOR NEW DELETE MEMORY MALLOC LIBRARY: MDV/Developer Source Code/C++ KEYWORDS: C++ OPERATOR NEW DELETE MEMORY MALLOC A replacement for the global operator new and operator delete implementations. From the comments in the code: ----- Advantages over MetroWerks's definition: 1. Memory is taken from the application heap or the temporary heap (preferrably the first) for greater flexibility. 2. Unused memory pools are released to the system. 3. Less fragmentation, because the MetroWerks delete operator doesn't always join adjacent free blocks. 4. If pool allocation fails, new doesn't revert to calling NewPtr for each block. It's a good thing, because otherwise the program would just slow down to a crawl (NewPtr is much slower than new) and die a horrible death, should the Toolbox run out of space. Finally, I keep a count of used blocks and free blocks, which can help assess the program's memory usage and fragmentation. ----- I have used this code in my own projects and it works beautifully. The source is easy to read and gives you a good starting point for tinkering with the global allocator, or gathering statistics for tuning & debugging. Posted with permission from the author. According to him the code can be freely used and distributed, but he asks that his name and email address are left in the source file. Gregory Jorgensen MDV Forum Consultant ------------------------------------------------------------ Macintosh Developers Forum Libraries Go Keyword: MDV This file has been checked for viruses with Disinfectant 3.6